package com.study.spmongodb.book.wwj.char23;

import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
 * @author MI
 * @version 1.0
 * @date 2020/11/30 20:58
 */
public class ProgrammerTravel extends Thread {
    //门阀
    private final Latch latch;

    private final String programmer;

    private final String transportation;

    public ProgrammerTravel(Latch latch, String programmer, String transportation) {
        this.latch = latch;
        this.programmer = programmer;
        this.transportation = transportation;
    }

    @Override
    public void run() {

        System.out.println(programmer + " start take the transportation" +
                "[" + transportation + "] ");

        try {
            TimeUnit.SECONDS.sleep(ThreadLocalRandom.current().nextInt(10));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(programmer + " arrived by  " + "[" + transportation + "] ");

        try {

            latch.countDown();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }
}
